package clientGUI.userPanels.Controllers;


import java.util.ArrayList;

import college.RequestTreatment.RequestStage;
import college.User;
import college.general;
import college.RequestTreatment;
import clientGUI.Controllers.Controller;
import clientserver.*;



public class InitiarorPanelController extends  Controller {

	private QueryResult req;
	private ArrayList<String> rids;
	private ArrayList<String> stages;
	private ArrayList<String> ridstoApprove;
	private User initiator;
	

	
	
	public ArrayList<String> getallRidstoAprove()
	{
		String q="SELECT * FROM Requests r , Request_details rd WHERE r.id = rd.id and rd.current_stage = '14' and r.initiator = "+general.addapostrophs(initiator.getLogin()); 
	  System.out.println(q);
		Packet p = new Packet(q);
	  QueryResult qr = (QueryResult) client.SendPacketAndWait(p);
	  for(int i=0;i<qr.rowsize();i++)
	  {
		  ridstoApprove.add(qr.getString("id"));
		  qr.next();

	  }
	return ridstoApprove;
	}
	
	
	public InitiarorPanelController(User u)
	{
		initiator = u;
		ridstoApprove= new ArrayList<String>();;
		rids= new ArrayList<String>();
		stages= new ArrayList<String>();
		
		
	}
	public void getallusersrid( User u)
	{
		String login=u.getLogin();
		 String q="SELECT * FROM  requests R, request_details D WHERE   R.id=D.id AND R.initiator="+general.addapostrophs(login);
		 Packet p=new Packet(q);

		  req=(QueryResult) client.SendPacketAndWait(p);
		  for(int i=0; i<req.rowsize();i++)
		  {
			  
				
				String cstage=req.getString("current_stage");
				String s=req.getString("id");
		rids.add(s);
		stages.add(cstage);
				req.next();
			}
		  
		  
	}
	
	public ArrayList<String>  getallrids()
	{
		return rids;
	}
	
	public String getStagedesctptionbyId(String id)
	{
		System.out.println("id="+id);
		int pos= rids.indexOf(id);
		System.out.println("pos="+pos);
		String s= stages.get(pos); //current_stage as a string
	
			int st=Integer.valueOf(s);  //current_stage as a integer 
		System.out.println("st="+st);
		return RequestTreatment.GetStageDescription(st);
	}
	
public void approveclosure(int rid)
{
RequestTreatment r = new RequestTreatment(client,rid);
r.loadfromdb();
r.setcurrentstage(16);
r.updatestageindb();

}
	

	
}
